package com.wgy.designmode.structure.filter.criteria;

import com.wgy.designmode.structure.filter.person.Person;

import java.util.List;

public class OrCriteria implements Criteria{

    private Criteria criteria;

    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> val1 = criteria.meetCriteria(persons);

        List<Person> val2 = otherCriteria.meetCriteria(persons);

        for (Person person : val2) {
            if (!val1.contains(person)){
                val1.add(person);
            }
        }
        return val1;
    }
}
